var inputData = [];
var allData = [];
var titleData=[];
init2(inputData);
function init2(data){
    $.ajax({
        type: "POST",
        url: "/bankingRegulatory/initData2",
        data:{city:'广州市'},
        // url: "/bankingRegulatory/businessRentPrice",
        // data:{city:410100},
        success: function (msg){
            if(msg.status=="false"){
                return
            }else{
                allData=msg.resultList;
                doCharts3();
            }
        }
    });
}
function doCharts3(){
    allData.forEach(function(data,index){
        titleData[index] = data.year;
    });
    var option5 = {
        baseOption: {
            timeline: {
                // y: 0,
                axisType: 'category',
                // realtime: false,
                // loop: false,
                autoPlay: false,
                currentIndex: titleData.length-1,
                playInterval: 1000,
                // controlStyle: {
                //     position: 'left'
                // },
                data: titleData,
                label: {
                    normal: {
                        color: '#ADADAD',
                    },
                },
            },
            title: {
                subtext: '商业用房价格及租金统计表',
                x: 'center'
            },
            tooltip: {
            },
            calculable : true,
            grid: {
                top: 80,
                bottom: 100,
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: '',
                        label: {
                            show: false,
                            formatter: function (params) {
                                return params.value.replace('\n', '');
                            }
                        }
                    }
                }
            },
            xAxis: [
                {
                    'type':'category',
                    'axisLabel':{'interval':0},
                    'data':[],
                    splitLine: {show: false},
                    axisLine:{
                        lineStyle:{
                            color:'#ADADAD',
                        }
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '金额/每平方米',
                    axisLine:{
                        lineStyle:{
                            color:'#ADADAD',
                        }
                    },
                }
            ],
            series: [
                {name: '价格', type: 'bar'},
                {name: '租金', type: 'bar'}
            ]
        },
        options: getOptions3()
    };
    var myChart = echarts.init($('#myChart6').get(0));
    myChart.setOption(option5);
    window.onresize = function () {
        myChart.resize()
    };
}
function getOptions3() {
    var option = [];
    allData.forEach(function(data,index){
        var series = [];
        var xAxisData =[];
        var seriesData=[];
        var seriesData1=[];
        data.priceList.forEach(function (data,index) {
            xAxisData[index]=data.distrcit_name;
            var ojb={
                name: data.distrcit_name,
                value:data.price
            };
            seriesData[index] = ojb;
            var ojb1={
                name: data.distrcit_name,
                value:data.rentprice
            };
            seriesData1[index] = ojb1;
        });
        var xAxis = {
            data:xAxisData
        };
        series[0] ={
            data:seriesData
        };
        series[1] ={
            data:seriesData1
        };
        var dataMap ={
            xAxis:xAxis,
            series:series
        };
        option[index] = dataMap;
    });
    return option;
}
//搜索
$('#searchData').click(function(){
    var citys = $('#city').val(),
        districts = $('#district').val(),
        loansBalanceStarts = $('#loansBalanceStart').val(),
        loansBalanceEnds =  $('#loansBalanceEnd').val(),
        loansAmountStarts = $('#loansAmountStart').val(),
        loansAmountEnds = $('#loansAmountEnd').val(),
        startDateStarts = $('#startDateStart').val(),
        startDateEnds = $('#startDateEnd').val(),
        loansDurations = $('#loansDuration').val(),
        risk = $('#risk').val(),
        buildAreaEnds = $('#buildAreaEnd').val(),
        buildAreaStarts = $('#buildAreaStart').val(),
        endDateStarts = $('#endDateStart').val(),
        endDateEnds = $('#endDateEnd').val(),
        inputData = {
            city:citys,
            district:districts,
            loansBalanceStart:loansBalanceStarts,
            loansBalanceEnd:loansBalanceEnds,
            loansAmountStart:loansAmountStarts,
            loansAmountEnd:loansAmountEnds,
            startDateStart:startDateStarts,
            startDateEnd:startDateEnds,
            loansDuration:loansDurations,
            risk:risk,
            buildAreaEnd:buildAreaEnds,
            buildAreaStart:buildAreaStarts,
            endDateStart:endDateStarts,
            endDateEnd:endDateEnds
        };
    init2(inputData)
});
